<?php
/**
 * 
 * @author Paolo Bertuzzo
 *
 */
namespace Catalog\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\Http\Header\RetryAfter;
use Zend\View\Model\ViewModel;
use Doctrine\ORM\EntityManager;
use Catalog\Service\ProductService;
use Utilities\Geolocation\GeolocationService;
use Catalog\Service\StoreService;
use Utilities\Session\SessionFacade;
use Catalog\Service\CollectionService;

/**
 */
class HomeController extends AbstractGeolocalizedController
{

    /**
     */
    protected $productService;

    /**
     */
    protected $collectionService;
    
    /**
     */
    protected $newItemsCount;
    
    /**
     * 
     * @param ProductService $productService
     * @param CollectionService $collectionService
     * @param GeolocationService $geolocationService
     * @param StoreService $storeService
     * @param int $newItemsCount
     */
    public function __construct(ProductService $productService, CollectionService $collectionService, GeolocationService $geolocationService, StoreService $storeService, $newItemsCount)
    {
        parent::__construct($geolocationService, $storeService);
        
        $this->productService = $productService;
        $this->collectionService = $collectionService;
        $this->newItemsCount = $newItemsCount;
    }

    /**
     *
     * @return A view model
     *        
     */
    public function homeAction()
    {
        $sessionFacade = new SessionFacade();
        
        $store = parent::getStore();
        
        return new ViewModel(array(
        	'new_products' => $this->productService->getNewProducts($store->getLanguage(), $this->newItemsCount, $store->getId()),
            'collections' => $this->collectionService->getAdvertised(20),
            'locale' => $sessionFacade->getLocale()
        ));
    }
    
}

?>